package com.cnzha.mr.order;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: zhaoxin
 * @email: zdkk@foxmail.com
 * @Date: 2020/4/4 18:51
 */
public class OrderMapper extends Mapper<LongWritable, Text, OrderBean, NullWritable> {

    private OrderBean orderBean = new OrderBean();
    private NullWritable nullWritable = NullWritable.get();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //0000001	Pdt_01	222.8
        String[] split = value.toString().split("\t");
        String orderId = split[0];
        String price = split[2];
        orderBean.setOrderId(Long.valueOf(orderId));
        orderBean.setPrice(Double.valueOf(price));
        context.write(orderBean, nullWritable);
    }
}
